package com.gator.desig_mode.command;



/**
 * @author 何章怀晓 hezhanghuaixiao
 * @version V1.0
 * @desc
 */
public abstract class Command {


  //这里只是简单参数，可封装抽取成类或枚举
  int open = 0;//打开

  int close = 1;//关闭

  int suspend = 2;//暂停

  int refrigeration = 3;//制冷

  private String name;

  public Command(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  protected Command() {
  }

  abstract void execute(int comm);

  abstract void undo();

}


class Computer extends Command {

  private Receiver receiver;

  public Computer(String name, Receiver receiver) {
    super(name);
    this.receiver = receiver;
  }

  public Computer(Receiver receiver) {
    this.receiver = receiver;
  }

  @Override
  public void execute(int comm) {
    if (comm == 0) {
      receiver.open(getName());

    }
    if (comm == 1) {
      receiver.close(getName());

    }

    if (comm == 2) {
      receiver.suspend(getName());
    }


  }

  @Override
  public void undo() {
    receiver.undo(getName());
  }

}

class Refrigerator extends Command {

  private Receiver receiver;

  public Refrigerator(String name, Receiver receiver) {
    super(name);
    this.receiver = receiver;
  }

  public Refrigerator(Receiver receiver) {
    this.receiver = receiver;
  }

  @Override
  public void execute(int comm) {
    if (comm == 0) {
      receiver.open(getName());

    }
    if (comm == 1) {
      receiver.close(getName());

    }

    if (comm == 3) {
      receiver.refrigeration(getName());
    }


  }

  @Override
  public void undo() {
    receiver.undo(getName());
  }

}